package com.athui.bean.other;

import com.athui.bean.metadata.ColumnMetaData;

import java.math.BigDecimal;

/**
 * @description: TODO 数据质量报告
 * @autor: zhangzhonghui
 * @create: 2024-08-03 22:16
 * @Version: 1.0
 */
public class DataQualityResult {
    private static final int SCALE = 5;
    private static final int ROUNDING_MODE = BigDecimal.ROUND_DOWN;

    /**
     * @description: TODO  列名
     * @author: 阿辉大人
     * @create: 2024/8/3 22:19
     * @version: 1.0
    **/
    private String columnName;

    /**
     * @description: TODO  null值率
     * @author: 阿辉大人
     * @create: 2024/8/3 22:19
     * @version: 1.0
    **/
    private BigDecimal nullValueRate;
    /**
     * @description: TODO  空值率
     * @author: 阿辉大人
     * @create: 2024/8/3 22:19
     * @version: 1.0
    **/
    private BigDecimal emptyValueRate;

    /**
     * @description: TODO  重复率
     * @author: 阿辉大人
     * @create: 2024/8/3 22:19
     * @version: 1.0
    **/
    private BigDecimal repeatValueRate;
    /**
     * @description: TODO 完整率
     * null 和 空值 越少，数据越完整
     * @author: 阿辉大人
     * @create: 2024/8/3 22:32
     * @version: 1.0
    **/
    private BigDecimal completeRate;
    /**
     * @description: TODO 唯一性
     * @author: 阿辉大人
     * @create: 2024/8/3 22:32
     * @version: 1.0
    **/
    private BigDecimal uniqueRate;

    public DataQualityResult(ColumnMetaData metaData){
        this.columnName = metaData.getColumnName();

        BigDecimal totalCount = BigDecimal.valueOf(metaData.getTotalCount());
        BigDecimal nullValueCount = BigDecimal.valueOf(metaData.getNullValueCount());
        BigDecimal emptyValueCount = BigDecimal.valueOf(metaData.getEmptyValueCount());
        BigDecimal repeatValueCount = BigDecimal.valueOf(metaData.getRepeatValueCount());

        // null值率
        this.nullValueRate = nullValueCount.divide(totalCount, SCALE, ROUNDING_MODE);
        // 空值率
        this.emptyValueRate = emptyValueCount.divide(totalCount, SCALE, ROUNDING_MODE);
        // 重复率
        this.repeatValueRate = repeatValueCount.divide(totalCount, SCALE, ROUNDING_MODE);
        // 完整率，null 和 空值 越少，数据越完整
        this.completeRate = nullValueRate.add(emptyValueRate).divide(totalCount, SCALE, ROUNDING_MODE);
        // 唯一性
        this.uniqueRate=  new BigDecimal(metaData.getNotRepeatValueCount()).divide(totalCount,SCALE,ROUNDING_MODE);
    }

    public BigDecimal getNullValueRate() {
        return nullValueRate;
    }

    public BigDecimal getEmptyValueRate() {
        return emptyValueRate;
    }

    public BigDecimal getRepeatValueRate() {
        return repeatValueRate;
    }

    public BigDecimal getCompleteRate() {
        return completeRate;
    }

    public BigDecimal getUniqueRate() {
        return uniqueRate;
    }

    @Override
    public String toString() {
        return "DataQualityResult{" +
                "columnName='" + columnName + '\'' +
                ", nullValueRate=" + nullValueRate.toString() +
                ", emptyValueRate=" + emptyValueRate.toString() +
                ", repeatValueRate=" + repeatValueRate.toString() +
                ", completeRate=" + completeRate.toString() +
                ", uniqueRate=" + uniqueRate.toString() +
                '}';
    }
}
